package com.milhouz.findmydroid.bean;

import android.database.Cursor;
import android.os.Parcel;
import android.os.Parcelable;

import com.milhouz.findmydroid.db.AppConstants;
import com.milhouz.findmydroid.exception.DatabaseRequestException;

public class Character implements Parcelable {

	private int mId;
	private String mName;
	private String mDescription;
	private String mLang;
	private int mIsUser;
	private int mCategoryId;

	public Character() {
	}

	public Character(final String name) {
		this.mName = name;
	}

	public Character(final Cursor cursor) throws DatabaseRequestException {
		if (cursor != null) {
			mId = cursor.getInt(cursor.getColumnIndex(AppConstants.COLUMN_ID));
			mName = cursor.getString(cursor.getColumnIndex(AppConstants.COLUMN_NAME));
			mDescription = cursor.getString(cursor.getColumnIndex(AppConstants.COLUMN_DESCRIPTION));
			mLang = cursor.getString(cursor.getColumnIndex(AppConstants.COLUMN_LANG));
			mIsUser = cursor.getInt(cursor.getColumnIndex(AppConstants.COLUMN_IS_USER));
			mCategoryId = cursor.getInt(cursor.getColumnIndex(AppConstants.COLUMN_CATEGORY_ID));
		} else {
			throw new DatabaseRequestException("Category cursor null or empty");
		}
	}

	public int getId() {
		return mId;
	}

	public String getName() {
		return mName;
	}

	public void setId(int mId) {
		this.mId = mId;
	}

	public void setName(String mName) {
		this.mName = mName;
	}

	public void setLang(String mLang) {
		this.mLang = mLang;
	}

	public String getDescription() {
		return mDescription;
	}

	public String getLang() {
		return mLang;
	}

	public int getIsUser() {
		return mIsUser;
	}

	public int getCategoryId() {
		return mCategoryId;
	}

	@Override
	public void writeToParcel(Parcel parcel, int flag) {
		parcel.writeInt(mId);
		parcel.writeString(mName);
		parcel.writeString(mDescription);
		parcel.writeString(mLang);
		parcel.writeInt(mIsUser);
		parcel.writeInt(mCategoryId);
	}

	public static final Creator<Character> CREATOR = new Creator<Character>() {
		@Override
		public Character createFromParcel(Parcel source) {
			Character c = new Character();
			c.mId = source.readInt();
			c.mName = source.readString();
			c.mDescription = source.readString();
			c.mLang = source.readString();
			c.mIsUser = source.readInt();
			c.mCategoryId = source.readInt();
			return c;
		}

		@Override
		public Character[] newArray(int arg0) {
			return null;
		}
	};

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public String toString() {
		return "Character [mId=" + mId + ", mName=" + mName + ", mDescription=" + mDescription + ", mLang=" + mLang + ", mIsUser=" + mIsUser + ", mCategoryId="
				+ mCategoryId + "]";
	}

}
